package com.dragon.refect.classload;

/**
 * 演示class卸载的案例
 *
 * @author dragon
 * @since 2019/11/22
 */
public class ClassUnloadTest {

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException,
            InstantiationException, InterruptedException {
        MyClassLoader classLoader = new MyClassLoader("myClassLoader");
        classLoader.setPath("/Users/panlong/Downloads/");
        Class<?> clazz = classLoader.loadClass("com.dragon.refect.classload.ClassInitialization");
        System.out.println("MyTest3:" + clazz);
        System.out.println("MyTest3 hashcode:" + clazz.hashCode());
        System.out.println("===================================");
        classLoader = new MyClassLoader("myClassLoader");
        classLoader.setPath("/Users/panlong/Downloads/");
        clazz = classLoader.loadClass("com.dragon.refect.classload.ClassInitialization");
        System.gc();
        System.out.println("MyTest3:" + clazz);
        System.out.println("MyTest3 hashcode:" + clazz.hashCode());
        Object o = clazz.newInstance();
        System.out.println("打印对象:" + o);
        System.out.println(o instanceof Object);
        Thread.sleep(10000000);
    }
}
